<?php
/**
 * 如花拼团开源系统 -- 永久免费
 * =========================================================
 * 官方网址：http://www.phps.shop
 * 作者：光爵【API + 后台】 、 小草【小程序 + WAP】
 * QQ 交流群：728615087
 * Version：1.0.0
 */

namespace app\api\model;


use app\lib\exception\BaseException;
use think\model\concern\SoftDelete;
use app\lib\exception\SuccessMessage;
use think\Db;

class SchedulingDetail extends BaseModel
{
    use SoftDelete;
    protected $hidden = ['update_time','create_time'];
    protected $deleteTime = 'delete_time';
    protected $type = [
        'start_time'     =>  'timestamp:Y-m-d',
        'end_time'  =>  'timestamp:Y-m-d',
    ];

    //创建用户行程安排
    public static function CreateOne($post)
    {
        $SchedulingDetail=new SchedulingDetail;
        Db::startTrans();
        try {
            $res  = (empty($post['id'])) ? false : true;
            $SchedulingDetail->isUpdate($res)->save($post); //直接通过关联模型来新增
            Db::commit();
        }catch (\Exception $e) {
            Db::rollback();// 回滚事务
            throw new BaseException(['msg'=>'新增行程安排失败']);
        }
        return json(new SuccessMessage(), 201);
    }

    //删除用户行程安排
    public static function scheduling_detail_del($id)
    {
        $res = SchedulingDetail::destroy(['id'=>$id]);
        if(!$res){
            throw new BaseException(['删除错误']);
        }else{
            return json(new SuccessMessage(),201);
        }
    }

}